<template>
  <el-container>
    <el-header>
      <div>
        <i style="font-size: 32px" class="iconfont icon-kuajingdianshang"></i
        >&nbsp; 电商后台管理系统
      </div>
      <div>
        <i
          style="margin-right: 10px; font-size: 28px"
          class="iconfont icon-yonghu"
        ></i>
        <span style="letter-spacing: 1px; font-size: 18px"
          >欢迎您，{{ username }}用户</span
        >
        <el-button class="quit" @click="quit" style="letter-spacing: 3px"
          >退出</el-button
        >
      </div>
    </el-header>
    <el-container>
      <el-aside :width="iscoll ? '64px' : '200px'">
        <div class="top" @click="iscoll = !iscoll">|||</div>
        <el-menu
          default-active
          :collapse="iscoll"
          unique-opened
          :collapse-transition="false"
          background-color="#353D41"
          text-color="#fff"
          active-text-color="#00A0FF"
          router
        >
          <el-submenu
            :index="item.id + ''"
            v-for="item in menuList"
            :key="item.id"
          >
            <template slot="title">
              <i :class="iconsObj[item.id]"></i>
              <span>{{ item.authName }}</span>
            </template>
            <el-menu-item
              :index="'/' + itemChildren.path"
              v-for="itemChildren in item.children"
              :key="itemChildren.id"
              ><i class="el-icon-menu"></i
              >{{ itemChildren.authName }}</el-menu-item
            >
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      username:'',
      iscoll: false,
      menuList: [],
      iconsObj: {
        125: "el-icon-user",
        103: "el-icon-setting",
        101: "el-icon-goods",
        102: "el-icon-help",
        145: "el-icon-search",
      },
    };
  },
  methods: {
    quit() {
      this.$confirm('此操作将退出登录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          window.sessionStorage.removeItem("token");
          window.sessionStorage.removeItem("username");
          this.$router.push("/");
          this.$message({
            type: 'success',
            message: '退出登录成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消退出登录'
          });          
        });
      
    },
    async getData() {
      var { data: res } = await this.$http.get("menus");
      this.menuList = res.data;
    },
  },
  created() {
    this.getData();
    this.username = window.sessionStorage.getItem('username');
  },
};
</script>
<style >
img {
  vertical-align: middle;
}
.el-header div{
   display: flex;
  align-items: center;
}
.el-header {
  display: flex;
  justify-content: space-between;
  color: white !important;
  background-color: #353d41 !important;
}
.quit {
  background-color: #909399 !important;
  border: none !important;
  color: white !important;
  height: 40px;
  line-height: 40px;
}
.quit:hover {
  background-color: #b1b3b8 !important;
}
.top {
  font-size: 12px;
  line-height: 30px;
  letter-spacing: 3px;
  color: white;
  text-align: center;
  font-size: 12px;
  background-color: #485064;
  cursor: pointer;
}
.el-menu {
  border: none !important;
  text-align: left;
}
.el-menu-item {
  text-align: center;
}
.el-container {
  height: 100%;
}
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
  font-size: 21px;
}

.el-aside {
  background-color: #353d41;
  color: #333;
  text-align: center;
  line-height: 200px;
}
</style>
